
package ploy.compiler;

import java.util.*;

/**
 * Objects of class FrameSize represent information about how much stack space
 * and how many frame variables are used by a compiled expression.
 */
class FrameSize {
    
    public int maxS;
    public int maxV;

    /** Default constructor. */
    public FrameSize( int s, int v ) {
	maxS = s;
	maxV = v;
    }

    /**
     * Given two FrameSizes, return a FrameSize that has enough stack space
     * and frame variables for both of them (assuming one is invoked after
     * the other).
     */
    static FrameSize max( FrameSize a, FrameSize b ) {
	int maxS = Math.max( a.maxS, b.maxS );
	int maxV = Math.max( a.maxV, b.maxV );

	return new FrameSize( maxS, maxV );
    }

    /**
     * Adds n stack slots to the current FrameSize.
     */
    public FrameSize addS( int n ) {
	return new FrameSize( maxS + n, maxV );
    }

    /**
     * Given two FrameSizes, return a FrameSize that has enough stack space
     * and frame variables for both of them simultaneously.
     */
    public FrameSize add( FrameSize f ) {
	int newS = maxS + f.maxS;
	int newV = maxV + f.maxV;
	return new FrameSize( newS, newV );
    }


}
   